<?php 
	include "include.php";
	
	$isSecureAccess = SecurityManager::getUser() != null;
	
	if( $isSecureAccess ) {
		$userService = new UserService();
		$users = $userService->listActiveUsers();
		$user = new UserModel();
		$user = SecurityManager::getUser();
		
		$save = Scope::loadVar("action") == "save";
		
		if( $save ) {
			$messageService = new MessageService();
			$message = new MessageModel();
			
			$message->setDate(date("Y-m-d H:i:s"));
			$message->setIsAlert(false);
			$message->setIsRead(true);
			$message->setMessage(Scope::loadVar("message"));
			$message->setSubject('Enviado pelo Site');
			$message->setSendBySite(true);
			$message->setUser_id(Scope::loadVar("user_id"));
			
			$messageService->save($message);
			echo"<center>SMS enviado com sucesso!</center>";
		} else {		
?>	

<div id="sms">
	<h3>Envio de SMS</h3>
	<form method="POST" action="?option=sms&action=save">
		<table width="300px" cellspacing="0">
			<tr>
				<td class="label">Enviar para:</td>
				<td class="input">
					<select name="user_id" >
						<option>Selecione</option>
<?php 
					foreach( $users as $user ) {
?>															
						<option value="<?php echo $user->getId(); ?>"><?php echo $user->getLogin(); ?></option>
<?php 				
					}
?>
					</select>
				</td>
			</tr>
			<tr>
				<td class="label">Mensagem</td>
				<td class="input">
					<textarea rows="2" cols="22" name="message"></textarea>
				</td>
			</tr>
			<tr>
				<td colspan="2" class="input">
					<button type="reset">Reset</button>&nbsp;<button type="submit">Enviar</button>
				</td>
			</tr>
		</table>	
	</form>
</div>
<?php	}	
	} else {
		MessageManager::setError("Voc&ecirc; n&atilde;o tem permiss&atilde;o para acessar esta p&aacute;gina");
		Util::includeFile("error.php",true);
	}
?>